<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品苗种" prop="fryId">
        <el-input
          v-model="queryParams.fryId"
          placeholder="请输入产品苗种"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="productPutinList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="养殖池" align="center" prop="pondId" :formatter="pondIdFormat"/>
      <el-table-column label="养殖产品/入水日期" align="center" prop="cpmc" >
        <template slot-scope="scope">
          <span>{{scope.row.cpmc}} / {{ parseTime(scope.row.inDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { listProductPutin, getProductPutin, delProductPutin, addProductPutin, updateProductPutin, exportProductPutin } from "@/api/busi/productPutin";
  import { listFryInfo } from "@/api/busi/fryInfo";
  import { getUserProfile } from "@/api/system/user";
  import { getInfoByUser } from "@/api/busi/mainInfo";
  import { listCompanyStaff } from "@/api/busi/companyStaff";
  import { listPondInfo } from "@/api/busi/pondInfo";

  export default {
    name: "ProductPutin",
    components: {
    },
    data() {
      return {
        user:null,
        unitOptions:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 产品投放记录表格数据
        productPutinList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          fryId: null,
          pondId: null,
          mainId: null
        },
        companyStaffList:[],
        queryParamsCompanyStaff: {
          pageNum: 1,
          pageSize: 1000,
          mainId: null,
          name: null,
          staTypeId: null
        },
        fryInfoList: [],
        queryParamsFryInfo: {
          pageNum: 1,
          pageSize: 1000,
          mainId: null,
          proId: null,
        },
        pondInfoList: [],
        queryParamsPondInfo: {
          pageNum: 1,
          pageSize: 1000,
          barId: null,
          mainId: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getDicts("busi_unit").then(response => {
        this.unitOptions = response.data;
      });
      getUserProfile().then(response => {
        this.user = response.data;
        getInfoByUser({userId:this.user.userId}).then(response => {
          this.queryParams.mainId = response.data.id;
          this.queryParamsCompanyStaff.mainId = response.data.id;
          this.queryParamsFryInfo.mainId = response.data.id;
          this.queryParamsPondInfo.mainId = response.data.id;
          this.getList();
          this.getCompanyStaffs();
          this.getFryInfos();
          this.getPondInfos();
        });
      });
    },
    methods: {
      fryIdFormat(row){
        let that = this
        let actions = [];
        Object.keys(that.fryInfoList).some((key) => {
          if (that.fryInfoList[key].id == ('' + row.fryId)) {
            actions.push(that.fryInfoList[key].proId);
            return true;
          }
        })
        return actions.join('');
      },
      pondIdFormat(row){
        let that = this
        let actions = [];
        Object.keys(that.pondInfoList).some((key) => {
          if (that.pondInfoList[key].id == ('' + row.pondId)) {
            actions.push(that.pondInfoList[key].barName +` / `+ that.pondInfoList[key].room);
            return true;
          }
        })
        return actions.join('');
      },
      staffIdFormat(row){
        let that = this
        let actions = [];
        Object.keys(that.companyStaffList).some((key) => {
          if (that.companyStaffList[key].id == ('' + row.staffId)) {
            actions.push(that.companyStaffList[key].name);
            return true;
          }
        })
        return actions.join('');
      },
      getPondInfos() {
        listPondInfo(this.queryParamsPondInfo).then(response => {
          this.pondInfoList = response.rows;
        });
      },
      getFryInfos() {
        listFryInfo(this.queryParamsFryInfo).then(response => {
          this.fryInfoList = response.rows;
        });
      },
      getCompanyStaffs() {
        listCompanyStaff(this.queryParamsCompanyStaff).then(response => {
          this.companyStaffList = response.rows;
        });
      },
      /** 查询产品投放记录列表 */
      getList() {
        this.loading = true;
        listProductPutin(this.queryParams).then(response => {
          this.productPutinList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },

    }
  };
</script>
